<template>
    <div>
        <a-table
            :columns="fjColumns"
            :data-source="filesListData"
            bordered
            style="border-color: #d9d9d9;font-weight: 600;text-align: center;"
            :customRow="customRow">
            <span slot="operation_btn" slot-scope="text, record">
            <a-button class="blue-btn" @click="openFiles(record)" style="margin-right: 10px;">查看</a-button>
            <a-button class="blue-btn" @click="downloadFiles(record)">下载</a-button>
            </span>
        </a-table>
    </div>
</template>
<script>
import { axios } from '@/utils/request'
import { getMoreUserSignLinkList } from './service/index'
export default {
    props: {
        config:{
            type:Object,
            default:()=>{
                return {}
            },
            required:false,
        },
    },
    data() {
        return {
            filesListData: [],
            fjColumns: [
                {
                    title: '文件名',
                    dataIndex: 'fmc',
                    key: 'fmc',
                    align: 'center'
                },{
                    title: '文件类型',
                    dataIndex: 'fwjlx',
                    key: 'fwjlx',
                    align: 'center'
                },{
                    title: '上传时间',
                    dataIndex: 'fscsj',
                    key: 'fscsj',
                    align: 'center'
                },{
                    title: '上传人',
                    dataIndex: 'fscr',
                    key: 'fscr',
                    align: 'center'
                },{
                    title: '操作',
                    key: 'id',
                    scopedSlots: { customRender: 'operation_btn' },
                },
            ],
            qmImgList: [],
            displayList: [],
        }
    },
    mounted(){
        this.getData()
    },
    methods: {
        customRow() {
            return {
                style: {
                    'font-size' : '16px',
                    'text-align' : 'center'
                },
            }
        },
        getData(){
            axios({
                url: this.config.api,
                method:'get' ,
                params: {
                    ...this.config.paramet,
                },
                url_1:this.config.urlType?'':'outside',
                url_2:this.config.urlType?'outside':''
            }).then((res) => {})
        },
        // 预览
        openFiles(item){
            //console.log(item)
            if(item.fwjlx.indexOf('pdf') !== -1){
              //console.log()
              window.open(
                  bootConfig[process.env.NODE_ENV].locality_ApI2+YchConstant.SPZX_OA+'/oaFjzyk/downLoadOa?id='+item.id
              )
            } else {
              openFile({id:item.id}).then(res => {
                if(!res.success){
                      this.$message.warning('当前附件类型不支持预览,请下载查看')
                } else {
                    window.open(res.result.wordUrl, '_blank')
                }
              })
            }

        },
        // 下载附件
        downloadFiles(val){
            //console.log('下载',val)
            var that = this
            var fileName = val.fmc
            downLoadOa({id:val.id}).then((data) => {
                // //console.log(data)
                if (!data) {
                    that.$message.warning('文件下载失败')
                    return
                }
                let url = window.URL.createObjectURL(new Blob([data], { type: blobType.type[blobType.suffix.indexOf(val.fwjlx)] }))
                let link = document.createElement('a')
                link.style.display = 'none'
                link.href = url
                link.setAttribute('download', fileName)
                document.body.appendChild(link)
                link.click()
                document.body.removeChild(link) //下载完成移除元素
                window.URL.revokeObjectURL(url) //释放掉blob对象
                // this.vxModal.visabled = false;
            })
        },
    },
}
</script>
